// ui/ui-manager.js
export class UIManager {
  constructor(config) {
    this.config = config
    this.theme = config.get('content.ui.theme', 'light')
    this.initTheme()
  }

  initTheme() {
    // // 动态加载主题样式
     this.theme = this.config.get('content.ui.theme', 'light')
     console.log("🚀 ~ ui-manager.js:12 ~ UIManager ~ initTheme ~ this.theme:", this.theme)
     
    const theme = this.config.get(`content.ui.themes.${this.theme}`)
    console.log("🚀 ~ ui-manager.js:14 ~ UIManager ~ initTheme ~ theme:", theme)

    // 设置CSS变量
    Object.keys(theme).forEach(key => {
      document.documentElement.style.setProperty(
        `--${key}`,
        theme[key]
      )
    })

    // 适配不同APP的导航栏
    // this.adaptNavigationBar()
  }

  adaptNavigationBar() {
    const navConfig = this.config.get('ui.navigation')

    if (navConfig.hidden) {
      // 隐藏原生导航栏
      this.jsBridge.invoke('hideNavBar')
    } else {
      // 设置导航栏样式
      this.jsBridge.invoke('setNavBar', {
        title: navConfig.title,
        color: navConfig.color,
        backgroundColor: navConfig.backgroundColor
      })
    }
  }

  // 安全区域适配
  adaptSafeArea() {
    const safeArea = this.config.get('ui.safeArea', {})

    document.documentElement.style.setProperty(
      '--safe-area-top',
      `${safeArea.top || 0}px`
    )

    document.documentElement.style.setProperty(
      '--safe-area-bottom',
      `${safeArea.bottom || 0}px`
    )
  }
}